//
//  ViewController.m
//  AutoHome
//
//  Created by Flying meat on 9/10/15.
//  Copyright (c) 2015 CaoFeng. All rights reserved.
//

#import "ViewController.h"
#import "UIImageView+AFNetworking.h"
#import "HTTPRequestManager.h"
#import "TabBarViewController.h"
#import "welcomeAdtViewController.h"
@interface ViewController ()
{
    NSMutableArray *_dataArray;

    NSString*_detailStr;
}
@end

@implementation ViewController
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        _dataArray=[NSMutableArray new];
        _detailStr=nil;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self getWelcomeInforFromNET];
    [self performSelector:@selector(afterThreeSecondJumpTo) withObject:nil afterDelay:4];
   
    
}
-(void)afterThreeSecondJumpTo
{
    TabBarViewController *tab=[self.storyboard instantiateViewControllerWithIdentifier:@"TabBarViewController"];
    tab.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
    [self presentViewController:tab animated:YES completion:nil];
    
    
    
    
}
- (BOOL)prefersStatusBarHidden

{
    return YES;//隐藏为YES，显示为NO
    
}

-(void)getWelcomeInforFromNET
{
    
    
    //在UIViewController的子类下调用:
    //在试图切换,比如addsubview,present,pushin等,也要注意以及修改状态栏
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
        
        // iOS 7
        
        [self prefersStatusBarHidden];
        
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
        
    }
    
    [[HTTPRequestManager shareInstance]getWelcomeInforSuccess:^(id responseObject) {

        
        [self.imgView setImageWithURL:[NSURL URLWithString:responseObject[@"imgurl"]]];
        
        _detailStr=responseObject[@"openurl"];
        self.imgView.userInteractionEnabled=YES;
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(touchToWebView)];
        [self.imgView addGestureRecognizer:tap];
        
        
    } failure:^(NSError *error) {
        NSLog(@"error=%@",error);
    }];
    
    
    
}
-(void)touchToWebView
{
    welcomeAdtViewController *welcomeAdt=[self.storyboard instantiateViewControllerWithIdentifier:@"welcomeAdtViewController"];
    
    welcomeAdt.openurl=_detailStr;
    welcomeAdt.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:welcomeAdt animated:YES completion:nil];

    
    
    
}

- (IBAction)JumpTo:(id)sender {
    TabBarViewController *tab=[self.storyboard instantiateViewControllerWithIdentifier:@"TabBarViewController"];
    tab.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
    [self presentViewController:tab animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
